package com.bw.database.db

import androidx.room.AutoMigration
import androidx.room.Database
import androidx.room.RenameColumn
import androidx.room.RenameTable
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.room.migration.AutoMigrationSpec
import com.bw.database.dao.UserInfoDao
import com.bw.database.dao.VideoInfoDao
import com.bw.database.table.UserDaoEntity

/**
 * 数据库实体
 */
@Database(
    entities = [UserDaoEntity::class],//数据库中包含哪些表格的实体对象
    version = 1,//数据库版本号
    exportSchema = false,//是否导出数据库
    autoMigrations = [
//        AutoMigration(from = 1, to = 2, spec = AppDataBase.UserInfoAutoMigration::class),
//        AutoMigration(from = 1, to = 2, spec = AppDataBase.UserInfoColumnAutoMigration::class),
    ]//数据库升级

)
abstract class AppDataBase:RoomDatabase() {
    abstract fun getUserInfoDao():UserInfoDao
    abstract fun getVideoInfoDao():VideoInfoDao

    //用于升级的时候修改表名
    @RenameTable(fromTableName = "user_table", toTableName = "user_info_table")
    class UserInfoAutoMigration:AutoMigrationSpec

    @RenameColumn(tableName = "user_table", fromColumnName = "name", toColumnName = "user_name")
    class UserInfoColumnAutoMigration:AutoMigrationSpec



}